<?php
/**
 * JoiGallery Плагины
 *
 * Плагин "Все фото в категории"
 * Выводит все фото из той же категории, что и
 * текущее изображение.
 *
 * @version 1.0
 * @package JoiGallery
 * @filename allcategoryphotos.php
 * @author JoostinaTeam
 * @copyright (C) 2008-2009 Joostina Team
 * @license see license.txt
 *
 **/
 
 class allCategoryPhotos {
    
    var $_object = null;
    var $_params = null;
    var $_mainframe = null;
    var $_config = null;
 
    function allCategoryPhotos($plugin, $plugin_config){
        $this->_object  = $plugin->object; 
        $this->_params  = $plugin->object_params;
        $this->_mainframe = $plugin->_mainframe;  
        $this->_config = $plugin_config;       
    }
    
    function show_content(){
        
        if($photos = $this->get_category_photos()){
            ?>
            <h3>Еще фото в категории</h3>

        	<ul>
    		<?php foreach($photos as $photo){

                $link = sefRelToAbs('index.php?option=' . $this->_params->_option . '&amp;act=photos&amp;cid=' .
                $photo->id . '&amp;Itemid=' . $this->_params->_Itemid);
       			
       			$photo->description = mosHTML::cleanText($photo->description);
       			$title = Text::character_limiter($photo->description, 100, '...');
      		?>
    		<!--Фото-->
    		<li class="photo">
    
    			<a class="photo_thumb" href="<?php echo $link; ?>" title="<?php echo $photo->description;?>">
     				<img src="<?php echo $this->_mainframe->getCfg('live_site') . $this->_params->thumbnail_path . '/' . $photo->path; ?>" border="0"
    				alt="<?php echo $photo->name; ?>" title="<?php echo $title; ?>" />
    			</a>
    
       			<?php if($this->_params->get('image_name_cat_view', 1)): ?>
    			   <h4><a href="<?php echo $link; ?>" title="<?php echo _SHOW . ' ' .$photo->name;?>"><?php  echo $photo->name; ?></a></h4>
    			<?php endif;?>
    
    			<?php if($this->_params->get('image_desc_cat_view', 0) ) : ?>
    				<p><?php echo $photo->description; ?></p>
    			<?php endif;?>
    
    		</li>
    		<!--/Фото-->
    		
      	<?php } ?>
        </ul>
           
        <?php
        }

        ?>
        
        
        <?php

    }
    
    function get_category_photos($limit = ''){
        
        $database = &database::getInstance();
        
        if($limit){
            $limit = ' LIMIT '.$limit;
        }
        
    	$query = 'SELECT id, ordering,  description, path, name FROM #__joigallery 
      	WHERE cid = ' . (int)$this->_object->cid . ' AND state = 1  AND id != ' . (int)$this->_object->id .' 
      	ORDER BY ordering DESC '.$limit;

        $database->setQuery( $query );
        return $database->loadObjectList();   
                
    }
    
 }
 
 
 ?>
